package com.panasonic.cn.cmsc;

import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;
import java.sql.SQLException;
import com.fujitsu.fks.jaaf.core.*;

public class SQLMUSR03{
	private Hashtable paramsString     = new Hashtable();
	private Hashtable paramsBigDecimal = new Hashtable();
	private Hashtable paramsFree       = new Hashtable();
	private String lastSql_ = null;

	private String getString(String name){
		if(name==null) return "";
		String returnStr = (String)paramsString.get(name);
		if(returnStr==null) return "";
		return "'"+FrameworkCommon.stringReplaceSQuote(returnStr)+"'";
	}

	private String getBigDecimal(String name){
		if(name==null) return "";
		BigDecimal returnStr = (BigDecimal)paramsBigDecimal.get(name);
		if(returnStr==null) return "";
		return returnStr.toString();
	}

	private String getFree(String name){
		if(name==null) return "";
		String returnStr = (String)paramsFree.get(name);
		if(returnStr==null) return "";
		return returnStr;
	}

	public String getLastSql(){
		return lastSql_;
	}

	public SelectResultRset SELECT_USR01(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("	SELECT ");
		sql.append("NVL( USER_ID,'') AS USER_ID,");
		sql.append("NVL( USER_NAME,'') AS USER_NAME,");
		sql.append("NVL( PASSWORD,'') AS PASSWORD,");
		sql.append("NVL( CTRL_DVSN_CD,'') AS CTRL_DVSN_CD,");
		sql.append("NVL( AUTH_LEVEL,'') AS AUTH_LEVEL,");
		sql.append("NVL( BSNS_TYP,'') AS BSNS_TYP,");
		sql.append("NVL( MAIL_ADDRESS,'') AS MAIL_ADDRESS,");
		sql.append("NVL( MAIL_SIZE,'') AS MAIL_SIZE,");
		sql.append("NVL( L_DSP_NO,'') AS L_DSP_NO,");
		sql.append("NVL( MENU_TYP,'') AS MENU_TYP,");
		sql.append("NVL( PSW_TEST,'') AS PSW_TEST,");
		sql.append("NVL( USER_AB_ID,'') AS USER_AB_ID,");
		sql.append("TO_CHAR(NVL( RGS_DTTM,''),'YYYYMMDDHH24MISS') AS RGS_DTTM,");
		sql.append("NVL( RGS_CHRG_CD,'') AS RGS_CHRG_CD,");
		sql.append("NVL( RGS_PGID,'') AS RGS_PGID,");
		sql.append("TO_CHAR(NVL( UPD_DTTM,''),'YYYYMMDDHH24MISS') AS UPD_DTTM,");
		sql.append("NVL( UPD_CHRG_CD,'') AS UPD_CHRG_CD,");
		sql.append("NVL( UPD_PGID,'') AS UPD_PGID ");
		sql.append("FROM USR ");
		sql.append("WHERE USER_ID "+((getString("USER_ID").equals(""))?" is null ":"=")+getString("USER_ID")+" ");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}

	public SelectResultRset SELECT_USR02(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("	SELECT ");
		sql.append("NVL( USER_ID,'') AS USER_ID,");
		sql.append("NVL( USER_NAME,'') AS USER_NAME,");
		sql.append("NVL( PASSWORD,'') AS PASSWORD,");
		sql.append("NVL( CTRL_DVSN_CD,'') AS CTRL_DVSN_CD,");
		sql.append("NVL( AUTH_LEVEL,'') AS AUTH_LEVEL,");
		sql.append("NVL( BSNS_TYP,'') AS BSNS_TYP,");
		sql.append("NVL( MAIL_ADDRESS,'') AS MAIL_ADDRESS,");
		sql.append("NVL( MAIL_SIZE,'') AS MAIL_SIZE,");
		sql.append("NVL( L_DSP_NO,'') AS L_DSP_NO,");
		sql.append("NVL( MENU_TYP,'') AS MENU_TYP,");
		sql.append("NVL( PSW_TEST,'') AS PSW_TEST,");
		sql.append("NVL( USER_AB_ID,'') AS USER_AB_ID,");
		sql.append("TO_CHAR(NVL( RGS_DTTM,''),'YYYYMMDDHH24MISS') AS RGS_DTTM,");
		sql.append("NVL( RGS_CHRG_CD,'') AS RGS_CHRG_CD,");
		sql.append("NVL( RGS_PGID,'') AS RGS_PGID,");
		sql.append("TO_CHAR(NVL( UPD_DTTM,''),'YYYYMMDDHH24MISS') AS UPD_DTTM,");
		sql.append("NVL( UPD_CHRG_CD,'') AS UPD_CHRG_CD,");
		sql.append("NVL( UPD_PGID,'') AS UPD_PGID ");
		sql.append("FROM USR ");
		sql.append("WHERE USER_ID "+((getString("USER_ID").equals(""))?" is null ":"=")+getString("USER_ID")+" ");
		sql.append("AND TO_CHAR(NVL( UPD_DTTM,''),'YYYYMMDDHH24MISS') "+((getString("UPD_DTTM").equals(""))?" is null ":"=")+getString("UPD_DTTM")+"");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}

	public int INSERT_BUSR03(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append(" INSERT INTO BUSR(");
		sql.append("SEQ_NO,");
		sql.append("USER_ID,");
		sql.append("USER_NAME,");
		sql.append("PASSWORD,");
		sql.append("CTRL_DVSN_CD,");
		sql.append("AUTH_LEVEL,");
		sql.append("BSNS_TYP,");
		sql.append("MAIL_ADDRESS,");
		sql.append("MAIL_SIZE,");
		sql.append("L_DSP_NO,");
		sql.append("MENU_TYP,");
		sql.append("PSW_TEST,");
		sql.append("USER_AB_ID,");
		sql.append("RGS_DTTM,");
		sql.append("RGS_CHRG_CD,");
		sql.append("RGS_PGID,");
		sql.append("UPD_DTTM,");
		sql.append("UPD_CHRG_CD,");
		sql.append("UPD_PGID,");
		sql.append("PSW_CHANGE_DTTM ");
		sql.append(") ");
		sql.append("select SEQ_BUSR.NEXTVAL,");
		sql.append("USER_ID,");
		sql.append("USER_NAME,");
		sql.append("PASSWORD,");
		sql.append("CTRL_DVSN_CD,");
		sql.append("AUTH_LEVEL,");
		sql.append("BSNS_TYP,");
		sql.append("MAIL_ADDRESS,");
		sql.append("MAIL_SIZE,");
		sql.append("L_DSP_NO,");
		sql.append("MENU_TYP,");
		sql.append("PSW_TEST,");
		sql.append("USER_AB_ID,");
		sql.append("RGS_DTTM,");
		sql.append("RGS_CHRG_CD,");
		sql.append("RGS_PGID,");
		sql.append("UPD_DTTM,");
		sql.append("UPD_CHRG_CD,");
		sql.append("UPD_PGID ,");
		sql.append("PSW_CHANGE_DTTM ");
		sql.append("FROM USR   ");
		sql.append("WHERE USER_ID "+((getString("USER_ID").equals(""))?" is null ":"=")+getString("USER_ID")+" ");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		int updateCount = db.executeUpdate();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return updateCount;
	}

	public int UPDATE_USR04(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("	UPDATE USR");
		sql.append("	SET ");
		sql.append("    USER_ID "+((getString("USER_ID").equals(""))?" is null ":"=")+getString("USER_ID")+",");
		sql.append("    USER_NAME "+((getString("USER_NAME").equals(""))?" is null ":"=")+getString("USER_NAME")+",");
		sql.append("    PASSWORD "+((getString("PASSWORD").equals(""))?" is null ":"=")+getString("PASSWORD")+",");
		sql.append("    CTRL_DVSN_CD "+((getString("CTRL_DVSN_CD").equals(""))?" is null ":"=")+getString("CTRL_DVSN_CD")+",");
		sql.append("    AUTH_LEVEL "+((getString("AUTH_LEVEL").equals(""))?" is null ":"=")+getString("AUTH_LEVEL")+",");
		sql.append("    BSNS_TYP "+((getString("BSNS_TYP").equals(""))?" is null ":"=")+getString("BSNS_TYP")+",");
		sql.append("    MAIL_ADDRESS "+((getString("MAIL_ADDRESS").equals(""))?" is null ":"=")+getString("MAIL_ADDRESS")+",");
		sql.append("    MAIL_SIZE "+((getString("MAIL_SIZE").equals(""))?" is null ":"=")+getString("MAIL_SIZE")+",");
		sql.append("    L_DSP_NO "+((getString("L_DSP_NO").equals(""))?" is null ":"=")+getString("L_DSP_NO")+",");
		sql.append("    MENU_TYP "+((getString("MENU_TYP").equals(""))?" is null ":"=")+getString("MENU_TYP")+",	");
		sql.append("    PSW_TEST "+((getString("PSW_TEST").equals(""))?" is null ":"=")+getString("PSW_TEST")+",	");
		sql.append("    USER_AB_ID "+((getString("USER_AB_ID").equals(""))?" is null ":"=")+getString("USER_AB_ID")+",		");
		sql.append("    RGS_DTTM = TO_DATE("+getString("RGS_DTTM")+",'YYYYMMDDHH24MISS'),");
		sql.append("    RGS_CHRG_CD "+((getString("RGS_CHRG_CD").equals(""))?" is null ":"=")+getString("RGS_CHRG_CD")+",");
		sql.append("    RGS_PGID "+((getString("RGS_PGID").equals(""))?" is null ":"=")+getString("RGS_PGID")+",");
		sql.append("    UPD_DTTM = TO_DATE("+getString("UPD_DTTM")+",'YYYYMMDDHH24MISS'),");
		sql.append("    UPD_CHRG_CD "+((getString("UPD_CHRG_CD").equals(""))?" is null ":"=")+getString("UPD_CHRG_CD")+",        ");
		sql.append("    UPD_PGID "+((getString("UPD_PGID").equals(""))?" is null ":"=")+getString("UPD_PGID")+" ");
		sql.append("    WHERE USER_ID "+((getString("USER_ID").equals(""))?" is null ":"=")+getString("USER_ID")+" ");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		int updateCount = db.executeUpdate();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return updateCount;
	}

	public SelectResultRset SELECT_USR05(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT VDR_CD  ");
		sql.append("FROM M01 ");
		sql.append("WHERE VDR_CD "+((getString("VDR_CD").equals(""))?" is null ":"=")+getString("VDR_CD")+" ");
		sql.append("AND FM_TYP "+((getString("FM_TYP1").equals(""))?" is not null ":"!=")+getString("FM_TYP1")+" ");
		sql.append("AND FM_TYP "+((getString("FM_TYP2").equals(""))?" is not null ":"!=")+getString("FM_TYP2")+" ");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}


	public void setUSER_ID(String value){
		if(value==null) {
			paramsString.remove("USER_ID");
			return;
		}
		paramsString.put("USER_ID",value);
	}


	public void setUPD_DTTM(String value){
		if(value==null) {
			paramsString.remove("UPD_DTTM");
			return;
		}
		paramsString.put("UPD_DTTM",value);
	}


	public void setUSER_NAME(String value){
		if(value==null) {
			paramsString.remove("USER_NAME");
			return;
		}
		paramsString.put("USER_NAME",value);
	}


	public void setPASSWORD(String value){
		if(value==null) {
			paramsString.remove("PASSWORD");
			return;
		}
		paramsString.put("PASSWORD",value);
	}


	public void setCTRL_DVSN_CD(String value){
		if(value==null) {
			paramsString.remove("CTRL_DVSN_CD");
			return;
		}
		paramsString.put("CTRL_DVSN_CD",value);
	}


	public void setAUTH_LEVEL(String value){
		if(value==null) {
			paramsString.remove("AUTH_LEVEL");
			return;
		}
		paramsString.put("AUTH_LEVEL",value);
	}


	public void setBSNS_TYP(String value){
		if(value==null) {
			paramsString.remove("BSNS_TYP");
			return;
		}
		paramsString.put("BSNS_TYP",value);
	}


	public void setMAIL_ADDRESS(String value){
		if(value==null) {
			paramsString.remove("MAIL_ADDRESS");
			return;
		}
		paramsString.put("MAIL_ADDRESS",value);
	}


	public void setMAIL_SIZE(String value){
		if(value==null) {
			paramsString.remove("MAIL_SIZE");
			return;
		}
		paramsString.put("MAIL_SIZE",value);
	}


	public void setL_DSP_NO(String value){
		if(value==null) {
			paramsString.remove("L_DSP_NO");
			return;
		}
		paramsString.put("L_DSP_NO",value);
	}


	public void setMENU_TYP(String value){
		if(value==null) {
			paramsString.remove("MENU_TYP");
			return;
		}
		paramsString.put("MENU_TYP",value);
	}


	public void setPSW_TEST(String value){
		if(value==null) {
			paramsString.remove("PSW_TEST");
			return;
		}
		paramsString.put("PSW_TEST",value);
	}


	public void setUSER_AB_ID(String value){
		if(value==null) {
			paramsString.remove("USER_AB_ID");
			return;
		}
		paramsString.put("USER_AB_ID",value);
	}


	public void setRGS_DTTM(String value){
		if(value==null) {
			paramsString.remove("RGS_DTTM");
			return;
		}
		paramsString.put("RGS_DTTM",value);
	}


	public void setRGS_CHRG_CD(String value){
		if(value==null) {
			paramsString.remove("RGS_CHRG_CD");
			return;
		}
		paramsString.put("RGS_CHRG_CD",value);
	}


	public void setRGS_PGID(String value){
		if(value==null) {
			paramsString.remove("RGS_PGID");
			return;
		}
		paramsString.put("RGS_PGID",value);
	}


	public void setUPD_CHRG_CD(String value){
		if(value==null) {
			paramsString.remove("UPD_CHRG_CD");
			return;
		}
		paramsString.put("UPD_CHRG_CD",value);
	}


	public void setUPD_PGID(String value){
		if(value==null) {
			paramsString.remove("UPD_PGID");
			return;
		}
		paramsString.put("UPD_PGID",value);
	}


	public void setVDR_CD(String value){
		if(value==null) {
			paramsString.remove("VDR_CD");
			return;
		}
		paramsString.put("VDR_CD",value);
	}


	public void setFM_TYP1(String value){
		if(value==null) {
			paramsString.remove("FM_TYP1");
			return;
		}
		paramsString.put("FM_TYP1",value);
	}


	public void setFM_TYP2(String value){
		if(value==null) {
			paramsString.remove("FM_TYP2");
			return;
		}
		paramsString.put("FM_TYP2",value);
	}


}
